<?php

//require_once("../../Logs/logs.php");
//echo "pase";
require_once '../../jqSuitePHP_4_1_2_2/jq-config.php';
//require_once ('/Applications/MAMP/htdocs/HS/jqSuitePHP_4_1_2_2/jq-config.php');
// include the jqGrid Class

require_once ABSPATH."php/jqGrid.php";
// include the driver class
require_once ABSPATH."php/jqGridPdo.php";
// Connection to the server
$conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD);
// Tell the db that we use utf-8
$conn->query("SET NAMES utf8");


// Create the jqGrid instance
$grid = new jqGridRender($conn);
// Write the SQL Query

$query= "SELECT idPaciente,pathFotoPaciente, Nombre, Apellido, TipoDoc, NumDoc FROM paciente " ;
//write_log("QueryGrid: ".$query." - grid.php");
$grid->SelectCommand = $query;

//echo $grid->SelectCommand ;
// Set the table to where you update the data
//$grid->table = 'paciente';


// Set output format to json
$grid->dataType = 'json';
// Let the grid create the model

$grid->setColModel();

$grid->setUrl("AgregarPaciente/BusquedaPaciente/grid.php");

// Set the url from where we obtain the data
// Set the url from where we obtain the data

/////     

// Set some grid options
$grid->setGridOptions(array(
    "caption"=>"Pacientes", 
        "width"=>600,
        "height"=>80,  
    "rowNum"=>10,
    "rowList"=>array(10,20,30),
    "sortname"=>"idPaciente"
));

$grid->setColProperty('idPaciente', array("label"=>"ID", "width"=>50));
$grid->setColProperty('pathFotoPaciente', array("label"=>"Photo","search"=>false, "width"=>50,"formatter"=>"js:formatImage", "unformat"=>"js:unformatImage"));
$grid->setColProperty('Nombre', array("label"=>"Nombres", "width"=>150));
$grid->setColProperty('Apellido', array("label"=>"Apellidos", "width"=>150));
$grid->setColProperty('TipoDoc', array("label"=>"Documento", "width"=>80));
$grid->setColProperty('NumDoc', array("label"=>"N&uacute;mero Documento", "width"=>145));

$selectorder = <<<Paciente
function(rowid, selected)
{
    if(rowid != null) {
        jQuery("#detail").jqGrid('setGridParam',{postData:{idPaciente:rowid}});
        jQuery("#detail").trigger("reloadGrid");
    }
}
Paciente;
$grid->setGridEvent('onSelectRow', $selectorder);

$grid->toolbarfilter = true; 
// Enable navigator


$pepe = <<<PEPE
jQuery("#getselected").click(function(){
    var selr = jQuery('#grid').jqGrid('getGridParam','selrow');
    
   if(selr) {
         window.location.href = "http://healthsolutions.com.ar/MainHCD.php?Pac="+selr;
	     window.open("http://healthsolutions.com.ar/DatosPacienteActual/HCPaciente/HCPacienteLectora/HCPacienteLectora.php?Pac="+selr);
	  
   }
    
    if(selr){
    //  window.location.href = "http://localhost/hs/MainHCD.php?Pac="+selr;
    //  window.open("http://localhost/hs/DatosPacienteActual/HCPaciente/HCPacienteLectora/HCPacienteLectora.php?Pac=" +selr);
    }
    
    if(selr) {
    //alert(selr);
    }
    else alert("No selected row");
    return false;
});

function formatImage(cellValue, options, rowObject) { 
    var imageHtml = "<img width='40px' height='40px' src='" + cellValue + "' originalValue='" + cellValue + "' />"; 
return imageHtml; 
} 
function unformatImage(cellValue, options, cellObject) { 
    return $(cellObject.html()).attr("originalValue"); 
} 
function formatRating(cellValue, options, rowObject) { 
    var color = (parseInt(cellValue) > 0) ? "green" : "red"; 
    var cellHtml = "<span style='color:" + color + "' originalValue='" + 
                   cellValue + "'>" + cellValue + "</span>"; 
    return cellHtml; 
} 
function unformatRating(cellValue, options, cellObject) { 
    return $(cellObject.html()).attr("originalValue"); 
} 
PEPE;
$grid->setJSCode($pepe); 
//$grid->setJSCode($custom); 


$grid->setSelect("TipoDoc", "SELECT DISTINCT TipoDoc, TipoDoc FROM paciente", 
false, false, true, array(""=>"Search"));


$grid->navigator = true;
// Enable only editing
//$grid->setNavOptions('navigator', array("excel"=>false,"add"=>false,"edit"=>false,"del"=>false,"view"=>false));

$grid->setNavOptions('navigator', array("excel"=>true,"add"=>true,"edit"=>true,"del"=>true,"view"=>true, "search"=>true));

// Enjoy
$grid->renderGrid('#grid','#pager',true, null, null, true,true);




// we set the select for ship city 

//$grid->setSelect("ShipCity", "SELECT DISTINCT ShipCity, ShipCity AS CityName FROM orders ORDER BY 2", false, false, true, array(""=>"All"))

$conn = null;
?> 
 


